package com.cdut.drivingschool.http.parser;

import org.json.JSONArray;
import org.json.JSONObject;

import com.cdut.drivingschool.bean.BaseType;
import com.cdut.drivingschool.bean.Group;
import com.cdut.drivingschool.bean.School;
import com.cdut.drivingschool.exception.ParserException;

public class SchoolParser extends BaseParser{

	@Override
	public BaseType parserObject(String json_data) throws ParserException {
		Group<School> schools = new Group<School>();
		try {
			JSONArray array = new JSONArray(json_data);
			for(int i = 0; i < array.length(); i++){
				JSONObject object = array.getJSONObject(i);
				School school = new School();
				school.school_logo = object.getString("school_logo");
				school.school_name = object.getString("school_name");
				school.school_pinfen = (float) object.getDouble("school_pinfen");
				school.school_pinlunnum = object.getInt("school_pinlunnum");
				school.school_youhuilogo = object.getInt("school_youhuilogo");
				school.school_branch = object.getString("school_branch");
				school.college = object.getString("college");
				school.school_newprice = object.getDouble("school_newprice");
				schools.add(school);
			}
		} catch (Exception e) {
			throw new ParserException("参数解析异常");
		}
		return schools;
	}
}
